<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/5
 * Time: 21:39
 */
namespace App\Demo\Controllers;

class HomeController extends BaseController
{
	public function __construct()
	{
		parent::__construct();
	}

	public function home($idd=0,$name='')
	{
		echo "<h1>HomeController home function 控制器加载成功！</h1>";
		echo "测试传递参数：<br />";
		var_dump ($idd);
		echo '<br />';
		var_dump ($name);
		echo '<br />';

		echo \Services\Route::urlBuild('demoName',array('id' => 10, 'name' => 'update')).'<br />';
		echo \Services\Route::getTplPath().'<br />';

		//$this->clearCache('app/demo/views/home.html');
		if ($this->isCached('app/demo/views/home.html')){
			echo "Smarty is Cached";
		}else{
			echo "Smarty is Not Cached";
		}

		$this->assign('title','this is smarty title test!中文测试');
		$this->display('app/demo/views/home.html');
		//$this->clearCache('app/demo/views/home.html');
	}

	public function doo()
	{
		$gump = new \GUMP();
		$_POST = $gump->sanitize($_POST);
		$gump->validation_rules(array(
			'fname' => 'required|numeric',
			'lname' => 'required|max_len,100|min_len,6'
		));
		$gump->filter_rules(array(
			'fname' => 'trim',
			'lname' => 'trim|md5'	// md5和字符数存在矛盾，bug，待修复
		));
		$validated_data = $gump->run($_POST);
		if ($validated_data === false){
			echo $gump->get_readable_errors(true);
		}else{
			print_r($validated_data);
		}
/**
		$is_valid = \GUMP::is_valid($_POST,array(
			'fname' => 'required|alpha_numeric',
			'lname' => 'required|max_len,100|min_len,6'
		));
		if ($is_valid === true){
			print_r($_POST);
		}else{
			print_r($is_valid);
		}
**/

		echo '<br />'.$_REQUEST['fname'].'<br />'.$_REQUEST['lname'].'<br />';
		echo "<h1>控制器加载成功！</h1>";
		echo \Services\Route::urlBuild('demoName',array('id' => 10, 'name' => 'update'));
	}
}